import { BaseCrudApi } from "~/api/util/BaseService";
import { User } from "~/api/system/user/types";
import { createAxios } from "~/api/util/request-wrapper";

export class UserApi extends BaseCrudApi<User> {
  baseUrl = "/system/user";

  getUserDetail(id: string) {
    this.detailState.form = {};
    this.beforeDetail(this.detailState);
    this.detailState.visible = true;
    if (id) {
      this.detailState.loading = true;
      this.get('/getUserDetail/' + id).then((res) => {
        this.detailState.form = res.data as any;
      }).catch((reason: any) => {
        console.log(reason);
      }).finally(() => {
        this.detailState.loading = false;
        this.afterDetail(this.detailState);
      });
    } else {
      this.afterDetail(this.detailState);
    }
  }
}

export function getUserMenu() {
  const http = createAxios();
  return http.get("/system/user-info/menu");
}
export function getUserCompany() {
  const http = createAxios();
  return http.get("/system/user-info/company");
}
